package com.app.couponsharelife.utils

import android.content.Context
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.RequestOptions
import com.app.couponsharelife.manage.Contacts

/**
 *Created by xct on 2019/1/14
 *Description:
 */
class LoadUtils {
    fun loadImag(context:Context,imageView: ImageView, url:String, errorimag:Int){
        var imgUrl = if (url!=null&&url.isNotEmpty()) {
            if (url.startsWith("//")) {
                Contacts.TCP + url
            } else if (url.startsWith("http")) {
                url
            } else {
                Contacts.REMOTE_IMAGE_URL + url
            }
        }else{
            url
        }
        Glide.with(context).asBitmap()
                .apply(RequestOptions().error(errorimag))
                .load(imgUrl)
                .into(imageView)
    }
    //加载普通图片
    fun loadCommonImag(context:Context,imageView: ImageView, url:String, errorimag:Int){
        Glide.with(context).asBitmap()
                .apply(RequestOptions()
                        .placeholder(errorimag)
                        .error(errorimag))
                .load(url)
                .into(imageView)
    }
    //加载圆角图片
    fun loadRoundImag(context:Context,imageView: ImageView, url:String, errorimag:Int,round:Int){
        Glide.with(context).asBitmap()
                .apply(RequestOptions().transforms(CenterCrop(), RoundedCorners( round))
                        .placeholder(errorimag).error(errorimag))
                .load(url)
                .into(imageView)
    }
}